package com.mashibing.singleton;

/**
 * 懒汉式
 * 虽然达到了按需初始化的目的，但却带来线程不安全的问题
 */
public class Mgro3 {
  public static Mgro3 INSTANCE;
  private Mgro3(){}
  public static Mgro3 getInstance(){
      if (INSTANCE==null){
          try{
              Thread.sleep(1);
          }catch (InterruptedException e){
              e.printStackTrace();
          }
          INSTANCE=new Mgro3();
      }
      return INSTANCE;
  }
    public void m(){
        System.out.println("m");
    }

    public static void main(String[] args) {
        for (int i=0;i<100;i++){
            new Thread(()->{
                System.out.println(Mgro3.getInstance().hashCode());
            }).start();
        }
    }
}
